home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Code Resources / NeXT MDEF / 3DPushIn.c++ next >
Encoding:
Text File  |  1994-03-09  |  5.2 KB  |  156 lines  |  [TEXT/KAHL]

  1. void DrawMenuItem(MenuHandle whichMenu, Rect *menuRect, short whichItem,
  2.                     MDEFconstants hiliteState, MDEFcolors *menuColors) {
  3.     Str255 itemText;
  4.     Rect itemRect;
  5.     Boolean itemDisabled;
  6.     short itemMarkOffset = 0;
  7.  
  8.     // Get text of menu item.
  9.     GetItem(whichMenu, whichItem, itemText);
  10.  
  11.     // Determine menu item's rect.
  12.     GetMenuItemRect(menuRect, &itemRect, whichItem);
  13.     // Do some rect clipping & fudging
  14.     InsetRect(&itemRect, rectPadding, rectPadding);
  15.     itemRect.right--;
  16.     itemRect.bottom--;
  17.  
  18.     // Catch special menu item cases, such as the dividing line "(-"
  19.     if (itemText[1] == '-') {
  20.         // Find height of menu item, divided by two
  21.         short halfWay = (itemRect.bottom - itemRect.top) >> 1;
  22.         // Draw top line (shadow)
  23.         RGBForeColor(&menuColors->dkGray);
  24.         MoveTo(itemRect.left  + 1, itemRect.top + halfWay);
  25.         LineTo(itemRect.right - 2, itemRect.top + halfWay);
  26.         // Draw bottom line (highlight)
  27.         RGBForeColor(&menuColors->white);
  28.         MoveTo(itemRect.left + 1, itemRect.top + halfWay + 1);
  29.         LineTo(itemRect.right - 2, itemRect.top + halfWay + 1);
  30.         // Restore colors
  31.         RGBForeColor(&menuColors->black);
  32.         return; // No more to draw, so exit
  33.     }
  34.  
  35.     itemDisabled = IsItemDisabled(whichMenu, whichItem);
  36.  
  37.     if (!itemDisabled) {
  38.         // If not disabled, draw the "3D box" surrounding menu item text...
  39.         if (hiliteState == unhilite)
  40.             RGBForeColor(&menuColors->white);
  41.         else
  42.             RGBForeColor(&menuColors->dkGray);
  43.         // Draw topleft shadow or highlight
  44.         MoveTo(itemRect.left, itemRect.top);
  45.         LineTo(itemRect.left, itemRect.bottom);
  46.         MoveTo(itemRect.left, itemRect.top);
  47.         LineTo(itemRect.right, itemRect.top);
  48.         if (hiliteState == unhilite)
  49.             RGBForeColor(&menuColors->dkGray);
  50.         else
  51.             RGBForeColor(&menuColors->white);
  52.         // Draw botRight shadow or highlight
  53.         MoveTo(itemRect.right, itemRect.top + 1);
  54.         LineTo(itemRect.right, itemRect.bottom);
  55.         MoveTo(itemRect.left + 1, itemRect.bottom);
  56.         LineTo(itemRect.right, itemRect.bottom);
  57.     }
  58.     RGBForeColor(&menuColors->ltGray);
  59.     InsetRect(&itemRect, 1, 1);
  60.     PaintRect(&itemRect);
  61.     InsetRect(&itemRect, -1, -1);
  62.  
  63.     // Draw item mark, if any. Remember to note if menu item is disabled or not
  64.     itemMarkOffset = StringWidth("\p√") + 4;
  65.     short theMark, theChar;
  66.     GetItemMark(whichMenu, whichItem, &theMark);
  67.     GetItemCmd(whichMenu, whichItem, &theChar);
  68.     if (theMark != noMark && theChar != hMenuCmd) {
  69.         // Not a submenu, but an actual item mark, so we have to draw it
  70.         if (hiliteState == hilite)
  71.             MoveTo(menuRect->left + widthPad, itemRect.bottom - heightPad + 1 + textHtPad);
  72.         else
  73.             MoveTo(menuRect->left + widthPad - 1, itemRect.bottom - heightPad + textHtPad);
  74.         RGBForeColor(&menuColors->black);
  75.         TextFont(systemFont);
  76.         if (itemDisabled)
  77.             TextMode(grayishTextOr);
  78.         DrawChar(theMark);
  79.         if (changeFont)
  80.             TextFont(menuFont);
  81.         if (itemDisabled)
  82.             TextMode(sysTextMode);
  83.     }
  84.  
  85.     // Now time to draw the menu item text itself...
  86.     if (itemDisabled) {
  87.         // If item is disabled, draw text that is grayed-out, via
  88.         // the grayishTextOr mode (available in System 7 only)
  89.         MoveTo(menuRect->left + widthPad - 1 + itemMarkOffset, itemRect.bottom - heightPad);
  90.         RGBForeColor(&menuColors->black);
  91.         // Set the gray-out mode
  92.         TextMode(grayishTextOr);
  93.         DrawString(itemText);
  94.         // Restore old text mode
  95.         TextMode(sysTextMode);
  96.     }
  97.     else {
  98.         // Draw normal menu item text...
  99.         RGBForeColor(&menuColors->black);
  100.         if (hiliteState == hilite) {
  101.             // Offset down & right by one pixel
  102.             MoveTo(menuRect->left + widthPad + itemMarkOffset, itemRect.bottom - heightPad + 1 + textHtPad);
  103.         }
  104.         else {
  105.             // Move to actual text position
  106.             MoveTo(menuRect->left + widthPad - 1 + itemMarkOffset, itemRect.bottom - heightPad + textHtPad);
  107.         }
  108.         DrawString(itemText);
  109.     }
  110.     
  111.     // Alright, time to draw Cmd-keys and/or submenu triangles
  112.     if (theChar == hMenuCmd) {
  113.         // Draw submenu symbol
  114.         Rect subMenuRect;
  115.         SetRect(&subMenuRect, 0, 0, subMenuWd, subMenuHt);
  116.         subMenuRect.top = (itemRect.top + ((itemRect.bottom - itemRect.top) >> 1)) - (subMenuHt >> 1);
  117.         subMenuRect.right = itemRect.right - rectPadding - 4;
  118.         subMenuRect.left = subMenuRect.right - subMenuWd;
  119.         subMenuRect.bottom = subMenuRect.top + subMenuHt;
  120.  
  121.         if (hiliteState == hilite)
  122.             OffsetRect(&subMenuRect, 1, 1);
  123.         short halfHeight = subMenuRect.top + ((subMenuRect.bottom - subMenuRect.top) >> 1);
  124.  
  125.         RGBForeColor(&menuColors->dkGray);
  126.         MoveTo(subMenuRect.left, subMenuRect.top);
  127.         LineTo(subMenuRect.right, halfHeight);
  128.         MoveTo(subMenuRect.left, subMenuRect.top);
  129.         LineTo(subMenuRect.left, subMenuRect.bottom);
  130.         RGBForeColor(&menuColors->white);
  131.         MoveTo(subMenuRect.left, subMenuRect.bottom);
  132.         LineTo(subMenuRect.right, halfHeight);
  133.         RGBForeColor(&menuColors->black);
  134.     }
  135.  
  136.  
  137.     // Draw cmd-key
  138.     else if (theChar != 0) {
  139.         short cmdWidth = StringWidth("\pW");    // "W" is widest character (I think)
  140.         cmdWidth += CharWidth(17);                // "Cmd" key character
  141.         if (hiliteState == hilite && !itemDisabled)
  142.             MoveTo(itemRect.right - (cmdKeyPad + cmdWidth) + 1, itemRect.bottom - heightPad + textHtPad + 1);
  143.         else
  144.             MoveTo(itemRect.right - (cmdKeyPad + cmdWidth), itemRect.bottom - heightPad + textHtPad);
  145.         TextFont(systemFont);
  146.         if (itemDisabled)
  147.             TextMode(grayishTextOr);
  148.         DrawChar(17);                        // ASCII = 17; command-key clover character
  149.         if (changeFont)
  150.             TextFont(menuFont);
  151.         DrawChar(theChar);
  152.         if (itemDisabled)
  153.             TextMode(sysTextMode);
  154.     }
  155.  
  156. } // END DrawMenuItem